package com.netty.io.nio;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NioSelectClientExample{

    public static void main(String[] args) throws Throwable {

        //开启client端的channel
        SocketChannel socketChannel = SocketChannel.open();

        //设置channel为非阻塞
        socketChannel.configureBlocking(false);

        //设置client端的ip和host
        InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1",6666);

        //开启client端的连接
        if(!socketChannel.connect(socketAddress)){
            while (!socketChannel.finishConnect()){
                System.out.println("连接尚未完成，客户端不阻塞，可以做其他工作");
            }
        }

        String str = "什么傻逼玩意";

        ByteBuffer byteBuffer = ByteBuffer.wrap(str.getBytes());

        //client发送数据，byteBuffer的数据写入channel
        socketChannel.write(byteBuffer);

        System.in.read();


    }
}
